
class RESTResource
	attr_reader :name, :params
	attr_writer :method, :name, :params
	
	def initialize
		@params = Hash.new
	end
	
	def isGET?
		@method == 'GET'
	end
	
	def isPUT?
		@method == 'PUT'
	end
	
	def isDELETE?
		@method == 'DELETE'
	end
	
	def [] k
		@params[k]
	end
	
	def []= k, v
		@params[k] = v
	end
	
end

class REST
	def self.getResource request, resource_name
		m = request.match(/^([A-Z]+?) \/#{resource_name}(.*) HTTP\/1.1$/)
		
		if m then
			rest = RESTResource.new
			rest.name = resource_name
			rest.method = m[1]
			if m = m[2].match(/^\?(.*)$/) then
				m[1].split('&').each do |var|
					key, value = var.split('=')
					rest[key] = value.to_i
				end
			end
			return rest
		end
		
		return nil
	end
end
